package com.scsj.supermarket.presenter;

import android.util.Log;

import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.DeliveryAddressBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.bean.DeliveryAddressBean;
import com.scsj.supermarket.model.DeliveryAddressModel;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 获取收货地址列表，删除收货地址，设置默认收货地址presenter
 */

public class DeliveryAddressPresenter extends BasePresenter implements DeliveryAddressBase.IPresenter {

    private DeliveryAddressBase.IModel mModel;
    private DeliveryAddressBase.IView mView;

    public DeliveryAddressPresenter(DeliveryAddressBase.IView view) {
        mView = view;
        mModel = new DeliveryAddressModel();
    }

    @Override
    public void deliverDAlistData(RequestBody requestBody) {

        addSubscription(mModel.getDAlistData(requestBody, new ResponseCallback<DeliveryAddressBean>() {
            @Override
            public void onSuccess(DeliveryAddressBean result) {

                if (result.getStatusCode() == 200) {

                    mView.showDASuccessMsg("获取成功", result);
                    Logger.d("收货地址列表获取成功" + result.toString());

                } else {
                    mView.showDAErrorMsg(result.getMsg());
                }

            }

            @Override
            public void onFaild(String msg) {
                mView.showDAErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverDeleteDAData(RequestBody requestBody) {
        addSubscription(mModel.getDeleteDAData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.deleteDASuccess("获取成功", result);
                    Logger.d("删除收货地址成功" + result.toString());
                } else {
                    mView.showDAErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showDAErrorMsg(msg);

            }
        }));
    }

    @Override
    public void deliverSetDefaultDAData(RequestBody requestBody) {
        addSubscription(mModel.getSetDefaultDAData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {

                if (result.getStatusCode() == 200) {
                    mView.setDefaultDASuccess("获取成功", result);
                    Logger.d("设置默认收货地址成功" + result.toString());
                } else {
                    mView.showDAErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showDAErrorMsg(msg);

            }
        }));
    }
}
